{{ extend 'layout.html' }}
{{ include 'catalog.html' }}


<h1>Checkout</h1>

{{ if not order: }}
<h2>No products in your shopping cart</h2>
{{ else: }}
<h2>Products in your shopping cart</h2>
<table>
    <tr>
        <th>Product</th>
        <th>Total</th>
    </tr>
    {{ for i, (product_id, qty, total_price, product, options) in enumerate(order): }}
    <tr>
        <td>
            {{= qty }} x {{= A(product.name, _href=URL(r=request, f='product', args=pretty_url(product.id, product.name))) }}
            <table>
        {{ for option in options: }}
                <tr>
                    <td>+ {{= option.description }}</td>
                    <td> ${{= option.price }}</td>
                </tr>
        {{ pass }}
            </table>
        </td>
        <td><h3>${{= total_price }}</h3></td>
        <td><a href="{{= URL(r=request, f='remove_from_cart', args=i) }}">remove</a></td>
    </tr>        
    {{ pass }}
    <tr>
        <td style="text-align:right"><h3>Balance:</h3></td>
        <td><h2>${{= "%.2f" % session.balance }}</h2></td>
</table>

<br/>
<br/>
<form name="google_form" action="https://checkout.google.com/cws/v2/Merchant/{{= merchant_id }}/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm">
    {{ for i, (product_id, qty, total_price, product, options) in enumerate(order): }}
    <input name="item_name_{{= i }}" type="hidden" value="{{= product.name }}"/>
    <input name="item_description_{{= i }}" type="hidden" value="{{= product.description }}"/>
    <input name="item_quantity_{{= i }}" type="hidden" value="{{= qty }}"/>
    <input name="item_price_{{= i }}" type="hidden" value="{{= total_price }}"/>
    <input name="item_weight_{{= i }}" unit="LB" type="hidden" value="{{= product.weight_in_pounds }}"/>
    <input name="item_currency_{{= i }}" type="hidden" value="USD"/>
    {{ pass }}

    <input name="_charset_" type="hidden" value="utf-8"/>

    <!-- fill in taxes and shipping options -->

    <input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id={{=merchant_id}}&amp;w=117&amp;h=48&amp;style=white&amp;variant=text&amp;loc=en_US" type="image" onclick="process(google_form);return false;"/>
</form>
{{ pass }}

<script language="text/javascript">
<!--
function process(form_name) {
    i = new Image()
    i.src = "/{{= request.application }}/default/empty_cart"; 
    form_name.submit();
}
//-->
</script>
{{ pass }}